﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MvcMall.Core.Contacts.Tasks;
using MvcMall.Core.Enums;

namespace MvcMall.AdminWeb.Manage.User
{
    public partial class UserDetail : ManageBasePage
    {
        private IUserTask _userTask;

        protected void Page_Load(object sender, EventArgs e)
        {
            ValidatePagePower("UserManager");
            _userTask = GetInstance<IUserTask>();
            if (!IsPostBack)
            {
                int id = -1;
                int.TryParse(Request["ID"], out id);
                if (id > 0)
                {
                    var model = _userTask.Get(id);
                    ltlUserName.Text = model.UserName;
                    ltlId.Text = model.Id.ToString();
                    ltlEmail.Text = model.Email;
                    ltlRealName.Text = model.RealName;
                    ltlSex.Text = model.Sex.Equals(Sex.男) ? "男" : "女";
                    ltlBirthday.Text = model.Birthday.ToString();
                    ltlPhone.Text = model.Phone;
                    ltlMobile.Text = model.Mobile;
                    ltlQQ.Text = model.QQ;
                    ltlReg.Text = model.RegTime.ToString();
                    ltlEmailChecked.Text = model.EmailChecked ? "是" : "否";
                    ltlEmailCheckCode.Text = model.EmailCheckCode;
                    ltlRealNameChecked.Text = model.RealNameChecked ? "是" : "否";
                    ltlIsLocked.Text = model.IsLocked ? "是" : "否";
                }else
                {
                    Page.ClientScript.RegisterClientScriptBlock(GetType(), "key",
                                                              "alert('提供ID错误！');window.location.href = '" +
                                                              Request.RawUrl + "'", true);
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Manage/User/UserList.aspx");
            Response.End();
        }
    }
}